using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using DiscMaster.Web.Models;

namespace DiscMaster.Web.Areas.Players.Controllers
{
    public class PlayersController : Controller
    {
        private IDiscMasterRepository repository;

        public PlayersController()
            : this(new DiscMasterRepository()){
        }

        public PlayersController(IDiscMasterRepository controllerrepository)
        {
            repository = controllerrepository;
        }

        //
        // GET: /Players/

        [OutputCache(CacheProfile = "ShortCache", VaryByParam = "none")]
        public ActionResult Index()
        {
            var players = repository.FindAllPlayers().ToList();
            if (players.Count==0)
            {
                return View("NoData");
            }
            return View("Index", players);
        }

        //
        // GET: /Players/Details/2
        [OutputCache(CacheProfile = "MediumCache", VaryByParam = "id")]
        public ActionResult Details(string id)
        {
            DiscMaster.Web.Models.Player player = repository.GetPlayerByName(id);
            if (player==null)
            {
                return View("NotFound");
            }
            return View("Details", player);
        }
    }
}
